<?php
/**
 * @file quote.php
 * @brief Provides a set of functions regarding to quotes
 */
require_once('../config.php');
require_once('db.php');
/**
add quote record into database

@param $file
	target quote file in pdf format

@param $title
	title for project
	
@return 
	quote id on success
*/
function addQuote($file, $title, $description){
	
	$now = date('Y-m-d H:i:s');
	/*
	int value for status to keep track of a quote
	0 = created
	1 = sent to client
	2 = viewed by client
	3 = approved by client
	*/
	$status = 0;
	if($file){
	}
	$insert_array = array(
					'title'			=> $title,
					'description' 	=> $description,
					'creation_date' => $now,
					'status'		=> $status 
					);
	DB::insert('quote', $insert_array);
	return DB::insertId();
	
}

/**
set quote status

@param $id
	target quote id
	
@param $status
	change quote status to $status
	
*/
function setQuoteStatus($id, $status){
	DB::update(
		'quote', 
		array(
	  		'status' => $status
	  	), 
	  	"id=%d", $id);
	echo 'quote status set to '.$status.'<br>';
	echo '	status:<br>
	0 = created<br>
	1 = sent to client<br>
	2 = viewed by client<br>
	3 = approved by client<br>
';
}


/**
progress quote to next stage by changing the status to status+1

@param $id
	target quote id
*/
function progressQuoteStatus($id){
	$current_status = DB::queryFirstField("SELECT `status` FROM `quote` WHERE `id`=%d", $id);
	$new_status = $current_status+1;
	
	DB::update(
		'quote', 
		array(
	  		'status' => $status
	  	), 
	  	"id=%d", $id);
	echo 'quote progress updated';
	
}


?>